From: tsteven4 Date: Thu, 27 Dec 2018 20:38:24 +0000 (-0700) Subject: enhance xcsv reader to not ignore LAT_DIR,LON_DIR. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~8^2~56^2 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=41224e6b15b6503e0629ea657ad0dfa35e01a0a5;p=gpsbabel.git enhance xcsv reader to not ignore LAT_DIR,LON_DIR. this came up on [Gpsbabel-misc] Globalsat DG-500. --- diff --git a/csv_util.cc b/csv_util.cc index 30d87d52b..84fd98bfa 100644 --- a/csv_util.cc +++ b/csv_util.cc @@ -169,6 +169,8 @@ static route_head* csv_track, *csv_route; static double utm_northing, utm_easting, utm_zone = 0; static char utm_zonec; static UrlLink* link_; +static gpsbabel_optional::optional lat_dir_positive; +static gpsbabel_optional::optional lon_dir_positive; #endif // CSVFMTS_ENABLED @@ -956,7 +958,7 @@ gmsd_init(Waypoint* wpt) /*****************************************************************************/ static void xcsv_parse_val(const char* s, Waypoint* wpt, const field_map& fmp, - route_head** trk) + route_head** trk, const int line_no) { const char* enclosure = ""; geocache_data* gc_data = nullptr; @@ -1060,10 +1062,24 @@ xcsv_parse_val(const char* s, Waypoint* wpt, const field_map& fmp, break; /* DIRECTIONS **********************************************************/ case XT_LAT_DIR: - /* latitude N/S. Ignore on input for now */ + /* latitude N/S. */ + if (*s == 'n' || *s == 'N') { + lat_dir_positive = true; + } else if (*s == 's' || *s == 'S') { + lat_dir_positive = false; + } else { + warning("parse of string '%s' on line number %d as LAT_DIR failed. Expected 'n', 'N', 's' or 'S'.\n", s, line_no); + } break; case XT_LON_DIR: - /* longitude E/W. Ingore on input for now */ + /* longitude E/W. */ + if (*s == 'e' || *s == 'E') { + lon_dir_positive = true; + } else if (*s == 'w' || *s == 'W') { + lon_dir_positive = false; + } else { + warning("parse of string '%s' on line number %d as LON_DIR failed. Expected 'e', 'E', 'w' or 'W'.\n", s, line_no); + } break; /* SPECIAL COORDINATES/GRID */ case XT_MAP_EN_BNG: @@ -1438,6 +1454,8 @@ xcsv_data_read() fatal(MYNAME ": attempt to read, but style '%s' has no IFIELDs in it.\n", CSTR(xcsv_file.description)? CSTR(xcsv_file.description) : "unknown"); } + lat_dir_positive.reset(); + lon_dir_positive.reset(); int ifield_idx = 0; /* now rip the line apart, advancing the queue for each tear @@ -1445,7 +1463,7 @@ xcsv_data_read() */ while (s) { const field_map& fmp = xcsv_file.ifields.at(ifield_idx++); - xcsv_parse_val(s, wpt_tmp, fmp, &trk); + xcsv_parse_val(s, wpt_tmp, fmp, &trk, linecount); if (ifield_idx >= xcsv_file.ifields.size()) { /* we've wrapped the queue. so stop parsing! */ @@ -1459,6 +1477,15 @@ xcsv_data_read() CSTR(xcsv_file.field_encloser), linecount); } + // If XT_LAT_DIR(XT_LON_DIR) was an input field, and the latitude(longitude) is positive, + // assume the latitude(longitude) was the absolute value and take the sign from XT_LAT_DIR(XT_LON_DIR). + if (lat_dir_positive.has_value() && !lat_dir_positive.value() && (wpt_tmp->latitude > 0.0)) { + wpt_tmp->latitude = -wpt_tmp->latitude; + } + if (lon_dir_positive.has_value() && !lon_dir_positive.value() && (wpt_tmp->longitude > 0.0)) { + wpt_tmp->longitude = -wpt_tmp->longitude; + } + if ((xcsv_file.gps_datum > -1) && (xcsv_file.gps_datum != GPS_DATUM_WGS84)) { double alt; GPS_Math_Known_Datum_To_WGS84_M(wpt_tmp->latitude, wpt_tmp->longitude, 0.0,